package com.jixiang.tracedata.controller;

import com.jixiang.tracedata.model.Error.OperationErr;
import com.jixiang.tracedata.model.traveller.Msg;
import com.jixiang.tracedata.service.FlightService;
import com.jixiang.tracedata.service.TraceService;
import com.jixiang.tracedata.service.TravellerService;
import com.jixiang.tracedata.util.StringOperate;
import com.jixiang.tracedata.util.XmlToBean;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @author quanbiao
 * @date 2018-09-11
 */
@RequestMapping("/action")
@RestController

public class TestController {

    @Autowired
    private TravellerService travellerService;

    @Autowired
    private TraceService traceService;

    @GetMapping(value = "/test")
    public void test(){
//
//        traceService.addFlightTraceMsg(null);
////        traceService.addTracellerTraceMsg(null);
//        System.out.println("直接返回");

    }

    @PostConstruct
    public void test111(){
        OperationErr operationErr = new OperationErr();
        String xml ="<Msg>\n" +
                "\t<Hdr>\n" +
                "\t\t<Ver>v1.0</Ver>\n" +
                "\t\t<Event>ActionCodeChange</Event>\n" +
                "\t\t<Subevent>CfmToCal</Subevent>\n" +
                "\t\t<Newval>NO</Newval>\n" +
                "\t\t<Oldval>HK</Oldval>\n" +
                "\t\t<Uptm>20180224230017</Uptm>\n" +
                "\t\t<Stamp>4ff2f3f8-40a1-4006-8193-3629d7660034</Stamp>\n" +
                "\t</Hdr>\n" +
                "\t<Dat>\n" +
                "\t\t<PassengerSegment>\n" +
                "\t\t\t<Traveller Type=\"ADT\" Vip=\"\">\n" +
                "\t\t\t\t<Surname>ZHANGXING</Surname>\n" +
                "\t\t\t\t<GivenName/>\n" +
                "\t\t\t\t<NativeGivenName>张行</NativeGivenName>\n" +
                "\t\t\t\t<Gender/>\n" +
                "\t\t\t\t<Document Surname=\"\" Initial=\"\" GivenName=\"\" Gender=\"\" Type=\"NI\" Number=\"371082198010171234\" IssueCountry=\"\" NationalityCountry=\"\" ExpirationDate=\"\" DateOfBirth=\"\" PassportHolder=\"\"/>\n" +
                "\t\t\t</Traveller>\n" +
                "\t\t\t<Segment ActionCode=\"NO\" CouponStatus=\"\" CouponNumber=\"\" NotValidBefore=\"\" NotValidAfter=\"\" EMDCouponStatus=\"\" InvoluntaryIndicator=\"\" BaggageAllowance=\"\">\n" +
                "\t\t\t\t<Carrier AirlineCode=\"FM\" FlightNumber=\"9353\" Suffix=\"\"/>\n" +
                "\t\t\t\t<OperatingCarrier AirlineCode=\"FM\" FlightNumber=\"9353\" Suffix=\"\"/>\n" +
                "\t\t\t\t<Departure AirportCode=\"PVG\" Date=\"2018-03-03\" Time=\"10:15:00\"/>\n" +
                "\t\t\t\t<Arrival AirportCode=\"WEH\" Date=\"2018-03-03\" Time=\"12:20:00\"/>\n" +
                "\t\t\t\t<Cabin Compartment=\"\" Clazz=\"V\"/>\n" +
                "\t\t\t\t<SpecialServiceRequest>\n" +
                "\t\t\t\t\t<SSRCode>FOID</SSRCode>\n" +
                "\t\t\t\t\t<ActionCode>HK1</ActionCode>\n" +
                "\t\t\t\t\t<AirlineCode>FM</AirlineCode>\n" +
                "\t\t\t\t\t<Text>NI371082198010171234</Text>\n" +
                "\t\t\t\t</SpecialServiceRequest>\n" +
                "\t\t\t\t<SpecialServiceRequest>\n" +
                "\t\t\t\t\t<SSRCode>FOID</SSRCode>\n" +
                "\t\t\t\t\t<ActionCode>HK1</ActionCode>\n" +
                "\t\t\t\t\t<AirlineCode>FM</AirlineCode>\n" +
                "\t\t\t\t\t<Text>NI371082198010171234</Text>\n" +
                "\t\t\t\t</SpecialServiceRequest>\n" +
                "\t\t\t\t<SpecialServiceRequest>\n" +
                "\t\t\t\t\t<SSRCode>ADTK</SSRCode>\n" +
                "\t\t\t\t\t<AirlineCode>CA</AirlineCode>\n" +
                "\t\t\t\t\t<Text>BY SHA25FEB18/2215 OR CXL FM9353 V03MAR</Text>\n" +
                "\t\t\t\t</SpecialServiceRequest>\n" +
                "\t\t\t\t<GeneralRemark Type=\"\">\n" +
                "\t\t\t\t\t<Text>NEW B2C</Text>\n" +
                "\t\t\t\t</GeneralRemark>\n" +
                "\t\t\t\t<OtherServiceInformation Type=\"FM\">\n" +
                "\t\t\t\t\t<Text>CTCT15000721234</Text>\n" +
                "\t\t\t\t</OtherServiceInformation>\n" +
                "\t\t\t\t<OtherServiceInformation Type=\"FM\">\n" +
                "\t\t\t\t\t<Text>CTCT15902111234</Text>\n" +
                "\t\t\t\t</OtherServiceInformation>\n" +
                "\t\t\t\t<OtherServiceInformation Type=\"FM\">\n" +
                "\t\t\t\t\t<Text>CTCT02151061234</Text>\n" +
                "\t\t\t\t</OtherServiceInformation>\n" +
                "\t\t\t\t<OtherServiceInformation Type=\"FM\">\n" +
                "\t\t\t\t\t<Text>CTCT02191234</Text>\n" +
                "\t\t\t\t</OtherServiceInformation>\n" +
                "\t\t\t\t<OtherServiceInformation Type=\"FM\">\n" +
                "\t\t\t\t\t<Text>CTCM95530</Text>\n" +
                "\t\t\t\t</OtherServiceInformation>\n" +
                "\t\t\t\t<Phone Type=\"CTCT\" Number=\"15000721234\"/>\n" +
                "\t\t\t\t<Phone Type=\"CTCT\" Number=\"15902111234\"/>\n" +
                "\t\t\t\t<Phone Type=\"CTCT\" Number=\"02151061234\"/>\n" +
                "\t\t\t\t<Phone Type=\"CTCT\" Number=\"02191234\"/>\n" +
                "\t\t\t\t<Phone Type=\"CTCM\" Number=\"95530\"/>\n" +
                "\t\t\t\t<Contact Type=\"C\" Number=\"95530\"/>\n" +
                "\t\t\t</Segment>\n" +
                "\t\t\t<BookingInfo BookingOffice=\"SHA777\" IataCode=\"\" GDSCode=\"\" GDSRecordLocator=\"\" RecordLocator=\"PDJJXW\" Group=\"N\" GroupName=\"\" BookDate=\"2018-02-24\" BookTime=\"14:15:00\"/>\n" +
                "\t\t</PassengerSegment>\n" +
                "\t</Dat>\n" +
                "</Msg>";
        try{
            Msg msg = XmlToBean.toBean(Msg.class, xml);
            traceService.addTravellerTraceMsg(xml, msg);
        }catch (Exception e){
            operationErr.setProcess("aaa");
        }
        finally {
            if(StringUtils.isNotBlank(operationErr.getProcess())){
                operationErr.setErrorXml("1111");
                traceService.addOperateErr(operationErr);
            }
        }
    }



}
